#include "music.h"
#include "ui_music.h"
#include <QPushButton>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
Music::Music(QWidget *parent)
    : QWidget(parent), ui(new Ui::Music)
{
    ui->setupUi(this);
    initui();
    connectsignalandslots();
}

Music::~Music()
{
    delete ui;
}

void Music::initui()
{
    this->setWindowFlag(Qt::FramelessWindowHint);
    // 设置窗口背景透明
    this->setAttribute(Qt::WA_TranslucentBackground);
    // 给窗口设置阴影
    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
    shadow->setOffset(0, 0);
    shadow->setColor("#000000");
    shadow->setBlurRadius(10);
    this->setGraphicsEffect(shadow);

    /* 设置不同btform 的 图标和文本信息*/
    ui->Rec->setIconAndText(":/image/rec.png","推荐",0);
    ui->audio->setIconAndText(":/image/radio.png","电台",1);
    ui->music->setIconAndText(":/image/music.png","音乐馆",2);

    ui->like->setIconAndText(":/image/like.png","喜欢",3);
    ui->local->setIconAndText(":/image/local.png","本地下载",4);
    ui->recent->setIconAndText(":/image/recent.png","最近播放",5);




}

void Music::connectsignalandslots()
{
    //关联 btfrom 信号和 处理该信号的槽函数
    connect(ui->Rec,&btform::btclick,this,&Music::onbtformclick);
  connect(ui->audio,&btform::btclick,this,&Music::onbtformclick);
    connect(ui->music,&btform::btclick,this,&Music::onbtformclick);
      connect(ui->like,&btform::btclick,this,&Music::onbtformclick);
        connect(ui->local,&btform::btclick,this,&Music::onbtformclick);
          connect(ui->recent,&btform::btclick,this,&Music::onbtformclick);



}

void Music::on_quit_clicked()
{
    this->close();
}

void Music::onbtformclick(int pageid)
{
    ui->stackedWidget->setCurrentIndex(pageid);
    qDebug()<<pageid;
}

void Music::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton)
    {
        move(event->globalPos() - dragPosition);
        return;
    }
    QWidget::mouseMoveEvent(event);// 未处理的事件交给父类处理
}

void Music::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        dragPosition = event->globalPos() - frameGeometry().topLeft();
        return;
    }
    QWidget::mousePressEvent(event);
}
